/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;

import util.LoggingUtils;

/**
 * 
 * @author Yang Wang <yang@digitalmenubox.com>
 */
public class HttpRequest {

	public static void postUpdateComplete() {
		final String classMethod = "HttpRequest .postUpdateComplete()";
		LoggingUtils.logStart(classMethod);
		
		try {
			HttpPostConnector c = new HttpPostConnector(new URL(model.Settings.UPDATE_CHECKER_URL),
					HttpPostConnector.getBoxToken() + "&reqtype=completeupdate");
			c.post();
		} catch (MalformedURLException ex) {
			LoggingUtils.log(Level.SEVERE, "Error in postUpdateComplete "+classMethod,ex);
			//ex.printStackTrace();
		}
		catch(Exception ex)
		{
			LoggingUtils.log(Level.SEVERE, "Error in postUpdateComplete "+classMethod,ex);
		}
	}

	public static void resendContent() {
		final String classMethod = "HttpRequest .resendContent()";
		LoggingUtils.logStart(classMethod);
		
		try {
			HttpPostConnector c = new HttpPostConnector(new URL(model.Settings.UPDATE_CHECKER_URL),
					HttpPostConnector.getBoxToken() + "&reqtype=resendcontent");
			c.post();
		} catch (MalformedURLException ex) {
			LoggingUtils.log(Level.SEVERE, ex.getMessage()+classMethod,ex);
			ex.printStackTrace();
		}
		catch(Exception ex)
		{
			LoggingUtils.log(Level.SEVERE, "Error in postUpdateComplete "+classMethod,ex);
		}
	}

	public static URL getWebtoolURL() {
		final String classMethod = "HttpRequest .getWebtoolURL()";
		LoggingUtils.logStart(classMethod);
		
		try {
			return new URL(model.Settings.UPDATE_CHECKER_URL);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			LoggingUtils.log(Level.SEVERE, e.getMessage()+classMethod,e);
			e.printStackTrace();
		}
		catch(Exception ex)
		{
			LoggingUtils.log(Level.SEVERE, "Error in postUpdateComplete "+classMethod,ex);
		}
		return null;
	}
	
	//RBB
	/**
	 * Temporary place holder copied from resendContent. It must be rewritten by Yang.
	 *
	 * Sends a short message to Digit Menubox server notifying that an unexpected exception or error
	 * has occurred.
	 */
	public static void sendLogNotification(String string) {
		final String classMethod = "HttpRequest .sendLogNotification()";
		LoggingUtils.logStart(classMethod);
		
		try {
			HttpPostConnector c = new HttpPostConnector(new URL(model.Settings.UPDATE_CHECKER_URL),
					HttpPostConnector.getBoxToken() + "&reqtype=sendLog");
			c.post();
		} catch (MalformedURLException ex) {
			LoggingUtils.log(Level.SEVERE, ex.getMessage()+classMethod,ex);
			ex.printStackTrace();
		}
		catch(Exception ex)
		{
			LoggingUtils.log(Level.SEVERE, "Error in postUpdateComplete "+classMethod,ex);
		}
	}			
}
